/*
               File: AnuReg
        Description: Anular Registro
             Author: GeneXus Java Generator version 8_0_9-040
       Generated on: 28 de Setiembre de 2010 17:21:38.41
       Program type: Callable routine
          Main DBMS: sqlserver
*/
import java.sql.*;
import com.genexus.db.*;
import com.genexus.*;
import com.genexus.distributed.*;

public final class panureg extends GXProcedure
{
   public panureg( int remoteHandle )
   {
      super( remoteHandle , new ModelContext( panureg.class ), "" );
   }

   public panureg( int remoteHandle ,
                   ModelContext context )
   {
      super( remoteHandle , context, "" );
   }

   public void execute( int aP0 ,
                        String aP1 ,
                        String aP2 ,
                        byte[] aP3 )
   {
      execute_int(aP0, aP1, aP2, aP3);
   }

   private void execute_int( int aP0 ,
                             String aP1 ,
                             String aP2 ,
                             byte[] aP3 )
   {
      panureg.this.AV8Codigo = aP0;
      panureg.this.AV11Codaux = aP1;
      panureg.this.AV10Tabla = aP2;
      panureg.this.aP3 = aP3;
      initialize();
      /* GeneXus formulas */
      /* Output device settings */
      if ( ( GXutil.strcmp(AV10Tabla, "MMCMB10") == 0 ) )
      {
         AV9Pout = 0 ;
         /* Using cursor P00112 */
         pr_default.execute(0, new Object[] {new Integer(AV8Codigo)});
         while ( (pr_default.getStatus(0) != 101) )
         {
            A523CmbCod = P00112_A523CmbCod[0] ;
            A579CmbEst = P00112_A579CmbEst[0] ;
            A579CmbEst = "0" ;
            AV9Pout = (byte)(1) ;
            /* Using cursor P00113 */
            pr_default.execute(1, new Object[] {A579CmbEst, new Integer(A523CmbCod)});
            /* Check if program is canceled. */
            /* Exiting from a For First loop. */
            if (true) break;
         }
         pr_default.close(0);
      }
      else if ( ( GXutil.strcmp(AV10Tabla, "MMTAU10") == 0 ) )
      {
         AV9Pout = 0 ;
         /* Using cursor P00114 */
         pr_default.execute(2, new Object[] {new Integer(AV8Codigo)});
         while ( (pr_default.getStatus(2) != 101) )
         {
            A376TipAut = P00114_A376TipAut[0] ;
            A378TipAut = P00114_A378TipAut[0] ;
            A378TipAut = "0" ;
            AV9Pout = (byte)(1) ;
            /* Using cursor P00115 */
            pr_default.execute(3, new Object[] {A378TipAut, new Byte(A376TipAut)});
            /* Check if program is canceled. */
            /* Exiting from a For First loop. */
            if (true) break;
         }
         pr_default.close(2);
      }
      else if ( ( GXutil.strcmp(AV10Tabla, "MMMRC10") == 0 ) )
      {
         AV9Pout = 0 ;
         /* Using cursor P00116 */
         pr_default.execute(4, new Object[] {AV11Codaux});
         while ( (pr_default.getStatus(4) != 101) )
         {
            A189MarCod = P00116_A189MarCod[0] ;
            A190MarEst = P00116_A190MarEst[0] ;
            if ( ( GXutil.strcmp(A189MarCod, GXutil.trim( AV11Codaux)) == 0 ) )
            {
               A190MarEst = "0" ;
               AV9Pout = (byte)(1) ;
               /* Using cursor P00117 */
               pr_default.execute(5, new Object[] {A190MarEst, A189MarCod});
            }
            /* Check if program is canceled. */
            pr_default.readNext(4);
         }
         pr_default.close(4);
      }
      cleanup();
   }

   protected void cleanup( )
   {
      this.aP3[0] = panureg.this.AV9Pout;
      exitApplication();
   }

   /* Aggregate/select formulas */
   public void initialize( )
   {
      AV9Pout = 0 ;
      P00112_A523CmbCod = new int[1] ;
      P00112_A579CmbEst = new String[] {""} ;
      A523CmbCod = 0 ;
      A579CmbEst = "" ;
      P00114_A376TipAut = new byte[1] ;
      P00114_A378TipAut = new String[] {""} ;
      A376TipAut = 0 ;
      A378TipAut = "" ;
      P00116_A189MarCod = new String[] {""} ;
      P00116_A190MarEst = new String[] {""} ;
      A189MarCod = "" ;
      A190MarEst = "" ;
      pr_default = new DataStoreProvider(context, remoteHandle, new panureg__default(),
         new Object[] {
             new Object[] {
            P00112_A523CmbCod, P00112_A579CmbEst
            }
            , new Object[] {
            }
            , new Object[] {
            P00114_A376TipAut, P00114_A378TipAut
            }
            , new Object[] {
            }
            , new Object[] {
            P00116_A189MarCod, P00116_A190MarEst
            }
            , new Object[] {
            }
         }
      );
      /* GeneXus formulas. */
      Gx_err = 0 ;
   }

   private byte AV9Pout ;
   private byte A376TipAut ;
   private short Gx_err ;
   private int AV8Codigo ;
   private int A523CmbCod ;
   private String AV11Codaux ;
   private String AV10Tabla ;
   private String A579CmbEst ;
   private String A378TipAut ;
   private String A189MarCod ;
   private String A190MarEst ;
   private byte[] aP3 ;
   private IDataStoreProvider pr_default ;
   private int[] P00112_A523CmbCod ;
   private String[] P00112_A579CmbEst ;
   private byte[] P00114_A376TipAut ;
   private String[] P00114_A378TipAut ;
   private String[] P00116_A189MarCod ;
   private String[] P00116_A190MarEst ;
}

final class panureg__default extends DataStoreHelperBase implements ILocalDataStoreHelper
{
   public Cursor[] getCursors( )
   {
      return new Cursor[] {
          new ForEachCursor("P00112", "SELECT [CmbCod], [CmbEst] FROM [MMCMB10] WITH (UPDLOCK) WHERE [CmbCod] = ? ",true, GX_NOMASK + GX_MASKLOOPLOCK, false, this,0,true )
         ,new UpdateCursor("P00113", "UPDATE [MMCMB10] SET [CmbEst]=?  WHERE [CmbCod] = ?", GX_NOMASK + GX_MASKLOOPLOCK)
         ,new ForEachCursor("P00114", "SELECT [TipAutCod], [TipAutEst] FROM [MMTAU10] WITH (UPDLOCK) WHERE [TipAutCod] = ? ",true, GX_NOMASK + GX_MASKLOOPLOCK, false, this,0,true )
         ,new UpdateCursor("P00115", "UPDATE [MMTAU10] SET [TipAutEst]=?  WHERE [TipAutCod] = ?", GX_NOMASK + GX_MASKLOOPLOCK)
         ,new ForEachCursor("P00116", "SELECT [MarCod], [MarEst] FROM [MMMRC10] WITH (UPDLOCK) WHERE [MarCod] = RTRIM(?) ORDER BY [MarCod] ",true, GX_NOMASK + GX_MASKLOOPLOCK, false, this,0,false )
         ,new UpdateCursor("P00117", "UPDATE [MMMRC10] SET [MarEst]=?  WHERE [MarCod] = ?", GX_NOMASK + GX_MASKLOOPLOCK)
      };
   }

   public void getResults( int cursor ,
                           IFieldGetter rslt ,
                           Object[] buf ) throws SQLException
   {
      switch ( cursor )
      {
            case 0 :
               ((int[]) buf[0])[0] = rslt.getInt(1) ;
               ((String[]) buf[1])[0] = rslt.getString(2, 1) ;
               break;
            case 2 :
               ((byte[]) buf[0])[0] = rslt.getByte(1) ;
               ((String[]) buf[1])[0] = rslt.getString(2, 1) ;
               break;
            case 4 :
               ((String[]) buf[0])[0] = rslt.getString(1, 10) ;
               ((String[]) buf[1])[0] = rslt.getString(2, 1) ;
               break;
      }
   }

   public void setParameters( int cursor ,
                              IFieldSetter stmt ,
                              Object[] parms ) throws SQLException
   {
      switch ( cursor )
      {
            case 0 :
               stmt.setInt(1, ((Integer) parms[0]).intValue());
               break;
            case 1 :
               stmt.setString(1, (String)parms[0], 1);
               stmt.setInt(2, ((Integer) parms[1]).intValue());
               break;
            case 2 :
               stmt.setInt(1, ((Integer) parms[0]).intValue());
               break;
            case 3 :
               stmt.setString(1, (String)parms[0], 1);
               stmt.setByte(2, ((Byte) parms[1]).byteValue());
               break;
            case 4 :
               stmt.setString(1, (String)parms[0], 10);
               break;
            case 5 :
               stmt.setString(1, (String)parms[0], 1);
               stmt.setString(2, (String)parms[1], 10);
               break;
      }
   }

}

